<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid">
		<!--{template /module/admin/view/head_nav}-->
		<div class="row-fluid">
			<div class="well widget">
				<div class="widget-header">
					<p class="text">* {lang admin.validate.require}</p>
				</div>
				<form method="post" action="{$ADMIN_SCRIPT}/wx/setting" onsubmit="javascript:return check_form(this);">
					<input type="hidden" name="formsubmit" value="yes" />
					<fieldset>
						<label>{lang wx.setting.view.open.label}</label>
						<!--{if $wx_setting['WX_OPEN'] == 0}-->
						<label class="checkbox inline">
							<input class="fancy" name="rdoIsOpen" type="radio" value="0" checked="checked" /> {lang wx.setting.view.open.no}
						</label>
						<label class="checkbox inline">
							<input class="fancy" name="rdoIsOpen" type="radio" value="1" /> {lang wx.setting.view.open.yes}
						</label>
						<!--{else}-->
						<label class="checkbox inline">
							<input class="fancy" name="rdoIsOpen" type="radio" value="0" /> {lang wx.setting.view.open.no}
						</label>
						<label class="checkbox inline">
							<input class="fancy" name="rdoIsOpen" type="radio" value="1" checked="checked" /> {lang wx.setting.view.open.yes}
						</label>
						<!--{/if}-->
						
						<div id="div_open" {if $wx_setting['WX_OPEN'] == 0}style="display:none;"{/if}>
							<hr />
							<label>{lang wx.setting.view.type.label}</label>
							<!--{if $wx_setting['WX_TYPE'] == 1}-->
							<label class="checkbox inline">
								<input class="fancy" name="rdoType" type="radio" value="0" /> {lang wx.setting.view.type.0}
							</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoType" type="radio" value="1" checked="checked" /> {lang wx.setting.view.type.1}
							</label>
							<!--{else}-->
							<label class="checkbox inline">
								<input class="fancy" name="rdoType" type="radio" value="0" checked="checked" /> {lang wx.setting.view.type.0}
							</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoType" type="radio" value="1" /> {lang wx.setting.view.type.1}
							</label>
							<!--{/if}-->
							<span class="help-inline">{lang wx.setting.view.type.tips}</span>
							
							<hr />
							<label>{lang wx.setting.view.account.label} *</label>
							<input type="text" class="input-xlarge" name="txtAccount" maxlength="40" value="{$wx_setting[WX_ACCOUNT]}" placeholder="{lang wx.setting.view.account.placeholder}…"/>
							<span class="help-inline">{lang wx.setting.view.account.tips}</span>
							
							<label>{lang wx.setting.view.passwd.label} *</label>
							<input type="password" class="input-xlarge" name="txtWxPasswd" maxlength="20" value="{$wx_setting[WX_PASSWD]}" placeholder="{lang wx.setting.view.passwd.placeholder}…"/>
							<span class="help-inline">{lang wx.setting.view.passwd.tips}</span>
							
							<label>{lang wx.setting.view.id.label} *</label>
							<input type="text" class="input-xlarge" name="txtId" maxlength="20" value="{$wx_setting[WX_ID]}" placeholder="{lang wx.setting.view.id.placeholder}…"/>
							<span class="help-inline">{lang wx.setting.view.id.tips}</span>
							
							<label>{lang wx.setting.view.token.label}</label>
							<input type="text" class="input-xlarge" name="txtToken" maxlength="32" value="{$wx_setting[WX_TOKEN]}" placeholder="{lang wx.setting.view.token.placeholder}…"/>
							<span class="help-inline">{lang wx.setting.view.token.tips}</span>
							
							<label>{lang wx.setting.view.appid.label}</label>
							<input type="text" class="input-xlarge" name="txtAppId" maxlength="32" value="{$wx_setting[WX_APPID]}" placeholder="{lang wx.setting.view.appid.placeholder}…"/>
							<span class="help-inline">{lang wx.setting.view.appid.tips}</span>
							
							<label>{lang wx.setting.view.appsecret.label}</label>
							<input type="text" class="input-xlarge" name="txtSecret" maxlength="32" value="{$wx_setting[WX_SECRET]}" placeholder="{lang wx.setting.view.appsecret.placeholder}…"/>
							<span class="help-inline">{lang wx.setting.view.appsecret.tips}</span>
							
							<hr />
							<label>{lang wx.setting.view.menu.label}</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoMenu" type="radio" value="1" {if $wx_setting['WX_MENU'] == 1}checked="checked"{/if}/> {lang wx.setting.view.menu.yes}
							</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoMenu" type="radio" value="0" {if $wx_setting['WX_MENU'] != 1}checked="checked"{/if}/> {lang wx.setting.view.menu.no}
							</label>
							<span class="help-inline">{lang wx.setting.view.menu.tips}</span>
							
							<hr/>
							<label>{lang wx.setting.view.auth.label}</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoAuth" type="radio" value="1" {if $wx_setting['WX_AUTH'] == 1}checked="checked"{/if}/> {lang wx.setting.view.auth.yes}
							</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoAuth" type="radio" value="0"{if $wx_setting['WX_AUTH'] != 1}checked="checked"{/if}/> {lang wx.setting.view.auth.no}
							</label>
							<span class="help-inline">{lang wx.setting.view.auth.tips}</span>
							
							<hr/>
							<label>{lang wx.setting.view.jssdk.label}</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoJSSDK" type="radio" value="1" {if $wx_setting['WX_JSSDK'] == 1}checked="checked"{/if}/> {lang wx.setting.view.jssdk.yes}
							</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoJSSDK" type="radio" value="0"{if $wx_setting['WX_JSSDK'] != 1}checked="checked"{/if}/> {lang wx.setting.view.jssdk.no}
							</label>
							<span class="help-inline">{lang wx.setting.view.jssdk.tips}</span>
							
							<hr/>
							<label>{lang wx.setting.view.msgtpl.label}</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoMsgTpl" type="radio" value="1" {if $wx_setting['WX_MSGTPL'] == 1}checked="checked"{/if}/> {lang wx.setting.view.msgtpl.yes}
							</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoMsgTpl" type="radio" value="0" {if $wx_setting['WX_MSGTPL'] != 1}checked="checked"{/if}/> {lang wx.setting.view.msgtpl.no}
							</label>
							<span class="help-inline">{lang wx.setting.view.msgtpl.tips}</span>
							
							<hr/>
							<label>{lang wx.setting.view.qrcode.label}</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoQRCode" type="radio" value="1" {if $wx_setting['WX_QRCODE'] == 1}checked="checked"{/if}/> {lang wx.setting.view.qrcode.yes}
							</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoQRCode" type="radio" value="0" {if $wx_setting['WX_QRCODE'] != 1}checked="checked"{/if}/> {lang wx.setting.view.qrcode.no}
							</label>
							<span class="help-inline">{lang wx.setting.view.qrcode.tips}</span>
							
							<hr/>
							<label>{lang wx.setting.view.payment.label}</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoPayment" type="radio" value="1" {if $wx_setting['WX_PAYMENT'] == 1}checked="checked"{/if}/> {lang wx.setting.view.payment.yes}
							</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoPayment" type="radio" value="0" {if $wx_setting['WX_PAYMENT'] != 1}checked="checked"{/if}/> {lang wx.setting.view.payment.no}
							</label>
							<span class="help-inline">{lang wx.setting.view.payment.tips}</span>
							<div id="div_payment" {echo $wx_setting['WX_PAYMENT'] ? '' : 'style="display:none;"';}>
								<hr/>
								<label>{lang wx.setting.view.payment.partnerid.label}</label>
								<input type="text" class="input" name="txtPartnerId" maxlength="100" value="{$wx_setting[WX_PARTNERID]}" placeholder="{lang wx.setting.view.payment.partnerid.placeholder}"/>
								<span class="help-inline">{lang wx.setting.view.payment.partnerid.tips}</span>
								
								<label>{lang wx.setting.view.payment.paykey.label}</label>
								<input type="text" class="input-xlarge" name="txtPartnerKey" maxlength="100" value="{$wx_setting[WX_PARTNERKEY]}" placeholder="{lang wx.setting.view.payment.paykey.placeholder}"/>
								<span class="help-inline">{lang wx.setting.view.payment.paykey.tips}</span>
								
								<label>{lang wx.setting.view.payment.pem.label}</label>
								<table class="swfupload">
									<tr id="tr_cert">
										<td>
											<input type="text" class="input" name="txtPemCert" data="{$wx_setting[WX_PEM_CERT][4]}" value="{$wx_setting[WX_PEM_CERT][1]}" readonly="readonly"/>
										</td>
										<td><p class="upload-button" style="width:180px;"><span id="swfu_cert"></span></p></td>
									</tr>
									<tr id="tr_key">
										<td>
											<input type="text" class="input" name="txtPemKey" data="{$wx_setting[WX_PEM_KEY][4]}" value="{$wx_setting[WX_PEM_KEY][1]}" readonly="readonly"/>
										</td>
										<td><p class="upload-button" style="width:180px;"><span id="swfu_key"></span></p></td>
									</tr>
									<tr id="tr_rootca">
										<td>
											<input type="text" class="input" name="txtPemRootCa" data="{$wx_setting[WX_PEM_ROOTCA][4]}" value="{$wx_setting[WX_PEM_ROOTCA][1]}" readonly="readonly"/>
										</td>
										<td><p class="upload-button" style="width:180px;"><span id="swfu_rootca"></span></p></td>
									</tr>
								</table>
							</div>
							
							<hr/>
							<label>{lang wx.setting.view.services.label}</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoServices" type="radio" value="1" {if $wx_setting['WX_SERVICES'] == 1}checked="checked"{/if}/> {lang wx.setting.view.services.yes}
							</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoServices" type="radio" value="0" {if $wx_setting['WX_SERVICES'] != 1}checked="checked"{/if}/> {lang wx.setting.view.services.no}
							</label>
							<span class="help-inline">{lang wx.setting.view.services.tips}</span>
							
							<hr/>
							<label>{lang wx.setting.view.voice.label}</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoVoice" type="radio" value="1" {if $wx_setting['WX_VOICE'] == 1}checked="checked"{/if}/> {lang wx.setting.view.voice.yes}
							</label>
							<label class="checkbox inline">
								<input class="fancy" name="rdoVoice" type="radio" value="0" {if $wx_setting['WX_VOICE'] != 1}checked="checked"{/if}/> {lang wx.setting.view.voice.no}
							</label>
							<span class="help-inline">{lang wx.setting.view.voice.tips}</span>
							
							<hr />
							<label>{lang wx.setting.view.api.label}</label>
							<p class="text-error">
								{$setting[SiteHost]}api.do?token={$wx_setting[WX_TOKEN]}
							</p>
					    </div>
					    
						<hr />
						
						<button type="submit" class="btn btn-small btn-primary" {$dispatches[operations][setup]}>{lang admin.operation.submit}</button>
						<button type="reset" class="btn btn-small">{lang admin.operation.reset}</button>
					</fieldset>
				</form>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript" src="static/plugins/swfupload.js"></script>
<script type="text/javascript" src="static/plugins/swfupload_handlers.js"></script>

<script>
var swfu_cert = null;
var swfu_key = null;
var swfu_rootca = null;

swfupload_params.limit = 1;
swfupload_params.uploaded = 0;

var _interval = null;

function fileQueueError(file, errorCode, message) {
	if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
		$.dialog({message:'{lang admin.validate.swfupload.lang.limit}'});
	}else{
		$.dialog({message:'{lang admin.validate.swfupload.echo.fail}'});
	}
}

function uploadSuccess(file, serverData) {
	if(serverData.substring(0, 7) === "FILEID:") {
		var tempArr = serverData.split('|');
		var filePath = formatFilePath(serverData.substring(7));
		$('#tr_' + tempArr[3] + ' input').val(tempArr[1]).attr('data', serverData.substring(7));
	}else $.dialog({message:serverData});
}

function createSwfUpload(type, title){
	var swf_config = {
		upload_url: "{$ADMIN_SCRIPT}/wx/setting/_upload&type=" + type + "&_SALT={$_var[current][SALT]}",
		
		file_size_limit : "100KB", 
		file_types : "*.pem;",
		file_types_description : "pem file",
		file_upload_limit : "0",
		
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		
		button_image_url : "static/images/swfupload/swfupload.png",
		button_placeholder_id : "swfu_" + type,
		button_width: 180,
		button_height: 18,
		button_text : '{lang admin.validate.swfupload.lang.button.choice}' + title,
		button_text_style : '',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		
		flash_url : "static/swfupload.swf", 
		debug: false
	};
	
	return new SWFUpload(swf_config);
}

function check_form(frm){
	if(frm.rdoIsOpen[1].checked){
		if(frm.txtAccount.value.trim().length == 0 && frm.txtAccount.value.trim().length == 0){
	    	$(frm.txtAccount).next('.help-inline').css('color', 'red');
	    	frm.txtAccount.focus();
	    	return false;
	    }
		
		if(frm.txtWxPasswd.value.trim().length == 0 && frm.txtWxPasswd.value.trim().length == 0){
	    	$(frm.txtWxPasswd).next('.help-inline').css('color', 'red');
	    	frm.txtWxPasswd.focus();
	    	return false;
	    }
		
		if(frm.rdoType[1].checked){
			if(frm.txtToken.value.trim().length == 0 && frm.txtToken.value.trim().length == 0){
		    	$(frm.txtToken).next('.help-inline').css('color', 'red');
		    	frm.txtToken.focus();
		    	return false;
		    }
			
			if(frm.txtAppId.value.trim().length == 0 && frm.txtAppId.value.trim().length == 0){
		    	$(frm.txtAppId).next('.help-inline').css('color', 'red');
		    	frm.txtAppId.focus();
		    	return false;
		    }
			
			if(frm.txtSecret.value.trim().length == 0 && frm.txtSecret.value.trim().length == 0){
		    	$(frm.txtSecret).next('.help-inline').css('color', 'red');
		    	frm.txtSecret.focus();
		    	return false;
		    }
		}
		
		if(frm.rdoPayment[0].checked){
			if(frm.txtPartnerId.value.trim().length == 0){
		    	$(frm.txtPartnerId).next('.help-inline').css('color', 'red');
		    	frm.txtPartnerId.focus();
		    	return false;
		    }
			
			if(frm.txtPartnerKey.value.trim().length == 0){
		    	$(frm.txtPartnerKey).next('.help-inline').css('color', 'red');
		    	frm.txtPartnerKey.focus();
		    	return false;
		    }
		}
	}
	
	frm.txtPemCert.value = $('#tr_cert input').attr('data');
	frm.txtPemKey.value = $('#tr_key input').attr('data');
	frm.txtPemRootCa.value = $('#tr_rootca input').attr('data');
	
	return true;
}

$(function(){
	$('.fancy').uniform();
	$("fieldset input[name='txtRegtime']").datepicker({format:'yyyy-mm-dd'});
	
	$('fieldset input,textarea,select').blur(function(){
		$(this).next('.help-inline').css('color', '#333');
	});
	
	$("input[name='rdoIsOpen']").click(function(){
		if($(this).val() == '0') $('#div_open').hide();
		else $('#div_open').show();
	});
	
	$("input[name='rdoPayment']").click(function(){
		if($(this).val() == '0') $('#div_payment').hide();
		else $('#div_payment').show();
	});
	
	$("input[name='rdoRemind']").click(function(){
		if($(this).val() == '0') $('#div_remind').hide();
		else $('#div_remind').show();
	});
	
	swfu_cert = createSwfUpload('cert', 'apiclient_cert.pem');
	swfu_key = createSwfUpload('key', 'apiclient_key.pem');
	swfu_rootca = createSwfUpload('rootca', 'rootca.pem');
});
</script>
<!--{template /module/admin/view/foot}-->